From 50b66608c9eaa88f4daafc7e3b03726ed31f2ef6 Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Thu, 1 Jul 2004 10:20:24 +0000 Subject: [PATCH] bitkeeper revision 1.1041.1.6 (40e3e568dXMUca5bKVlAd9SLsmVpEw) Release the channel and port when a domain is destroyed. Allows the domain to finally go away. --- tools/python/xen/xend/XendDomainInfo.py | 3 ++ tools/python/xen/xend/server/SrvDaemon.py | 9 +++++ tools/python/xen/xend/server/channel.py | 41 +++++++++++++++++------ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index e3e4e92cbd..c0de8fed01 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -504,6 +504,9 @@ class XendDomainInfo: devices have been released. """ if self.dom is None: return 0 + chan = xend.getDomChannel(self.dom) + if chan: + chan.close() return xc.domain_destroy(dom=self.dom) def cleanup(self): diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index 7dde51f68f..63c4dd1bee 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -663,6 +663,15 @@ class Daemon: reactor.diconnectAll() sys.exit(0) + def getDomChannel(self, dom): + """Get the channel to a domain. + + dom domain + + returns channel (or None) + """ + return self.channelF.getDomChannel(dom) + def blkif_set_control_domain(self, dom, recreate=0): """Set the block device backend control domain. """ diff --git a/tools/python/xen/xend/server/channel.py b/tools/python/xen/xend/server/channel.py index ecd9cf93f3..da19d621c2 100755 --- a/tools/python/xen/xend/server/channel.py +++ b/tools/python/xen/xend/server/channel.py @@ -48,15 +48,31 @@ class ChannelFactory: def domChannel(self, dom): """Get the channel for the given domain. Construct if necessary. + + dom domain + + returns channel + """ + chan = self.getDomChannel(dom) + if not chan: + chan = Channel(self, dom) + self.addChannel(chan) + return chan + + def getDomChannel(self, dom): + """Get the channel for the given domain. + + dom domain + + returns channel (or None) """ dom = int(dom) for chan in self.channels.values(): if not isinstance(chan, Channel): continue if chan.dom == dom: return chan - chan = Channel(self, dom) - self.addChannel(chan) - return chan + return None + def virqChannel(self, virq): """Get the channel for the given virq. @@ -109,12 +125,11 @@ class BaseChannel: def notificationReceived(self): """Called when a notification is received. - Closes the channel on error, otherwise calls - handleNotification(type), which should be defined + Calls handleNotification(), which should be defined in a subclass. """ - if not self.closed: - self.handleNotification(type) + if self.closed: return + self.handleNotification() def close(self): """Close the channel. Calls channelClosed() on the factory. @@ -122,7 +137,7 @@ class BaseChannel: """ self.factory.channelClosed(self) - def handleNotification(self, type): + def handleNotification(self): """Handle notification. Define in subclass. """ @@ -172,7 +187,7 @@ class VirqChannel(BaseChannel): """ self.clients.append(client) - def handleNotification(self, type): + def handleNotification(self): for c in self.clients: c.virqReceived(self.virq) @@ -221,13 +236,14 @@ class Channel(BaseChannel): """Close the channel. Calls lostChannel() on all its devices and channelClosed() on the factory. """ + if self.closed: return self.closed = 1 for d in self.devs: d.lostChannel() self.factory.channelClosed(self) self.devs = [] self.devs_by_type = {} - del self.port + self.port.disconnect() def registerDevice(self, types, dev): """Register a device controller. @@ -271,7 +287,10 @@ class Channel(BaseChannel): self.getLocalPort(), self.getRemotePort())) - def handleNotification(self, type): + def handleNotification(self): + if self.closed: + print 'handleNotification> Notification on closed channel', self + return work = 0 work += self.handleRequests() work += self.handleResponses() -- 2.30.2